var app = getApp()
Page({
  data: {
    userinfo: null,
    code: null,
    encryptedData: null,
    iv: null
  },
  //点击登录事件
  login: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    that.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userinfo: userInfo.userInfo,
        encryptedData: userInfo.encryptedData,
        iv: userInfo.iv
      })
    })
  },

  onShareAppMessage: function () {
    // 用户点击右上角分享
    return {
      title: 'title', // 分享标题
      desc: 'desc', // 分享描述
      path: 'path' // 分享路径
    }
  },
  //获取用户信息
  getUserInfo: function (cb) {
    var that = this
    if (this.data.userInfo) {
      typeof cb == "function" && cb(this.data.userInfo)
    } else {
      //调用登录接口f
      wx.login({
        success: function (res) {
          console.log(res);
          that.setData({ code: res.code });
          wx.getUserInfo({
            success: function (res) {
              that.data.userInfo = res
              typeof cb == "function" && cb(that.data.userInfo)
            }
          })
        }
      })
    }
  },

  //
  get3rdSession: function () {
    let that = this
    wx.request({
      url: 'https://localhost:8443/ntuserver/user_get3rdSession',
      data: {
        code: this.data.code,
        iv : this.data.iv,
        encryptedData : this.data.encryptedData
      },
       
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        console.log(res);
        // success
        //var sessionId = res.data.session;
        //that.setData({ sessionId: sessionId })
       // wx.setStorageSync('sessionId', sessionId)
        //that.decodeUserInfo()
      }
    })
  },
})